<?php


namespace app\common\model;


use think\Cache;

class AppChannelPackage extends Base
{
    protected $table = 'wechatadmin.system_app_channel_package';

    /**
     * 获取app版本更新信息,根据app型号和版本,若开启强制更新则返回渠道包号
     * @param array $map
     * @return array|bool|mixed
     */
    public function getChannel($version_code, $channel)
    {
        $data = false;
        if ($this->cache_on >= 1)
        {
            $data = Cache::get('app_channel' . $channel . '-' . $version_code);
        }

        if ($data === false)
        {
            try
            {
                $data = $this
                    ->field('app_version_code,channel_source,channel_link')
                    ->where(['app_version_code' => $version_code, 'channel_source' => $channel])
                    ->findOrFail();
            }
            catch (\Exception $e)
            {
                $channel = 'zhunle';
                $data = $this
                    ->field('app_version_code,channel_source,channel_link')
                    ->where(['app_version_code' => $version_code, 'channel_source' => $channel])
                    ->find();
            }
            Cache::set('app_channel' . $channel . '-' . $version_code, $data, 86400 * 3);
        }
        return $data;
    }

}